package com.infinitegroup.findmystuff.activities;

import com.infinitegroup.findmystuff.R;
import com.infinitegroup.findmystuff.views.RegistrationView;
import com.infinitegroup.findmystuff.presenters.AdminRegistrationPresenter;

import android.app.Activity;
import android.os.Bundle;
import android.view.Gravity;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;

/**
 * Handles the inputs of the admin registration screen and gives these inputs to the admin registration
 * controller (who actually handles changing the database).
 * 
 * @author Maria
 *
 */
public class AdminRegistrationActivity extends Activity implements RegistrationView{

	private AdminRegistrationPresenter presenter;
	

	/**
	 * Handles the start of the activity and sets the listeners for the buttons on the screen.
	 */
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_registration);

		this.presenter = new AdminRegistrationPresenter(this);
		
		Button b = (Button) findViewById(R.id.register_registration_button);

		//what happens when Register button is clicked
		b.setOnClickListener(new OnClickListener() {
			/**
			 * Handles the click of the registration button by calling onClick and finishing the activity.
			 */
			public void onClick(View v) {
				onRegisterClick();	
				finish();
			}
		});
	}

	/**
	 * Unused method.
	 */
	public void advanceToLogin() {
		//had to implement this because of the RegistrationView interface, but don't actually need to use it here
	}

	/**
	 * This method is a helper method that displays warning strings in a pop up window
	 */
	public void displayMessage(String string) {
		if (string!=null){
			Toast toast = Toast.makeText(this, string, Toast.LENGTH_LONG);
			toast.setGravity(Gravity.CENTER, 0, 0);
			toast.show();
		}
	}

	/**
	 * This method passes all the info in the registration screen onto the presenter.
	 */
	public void onRegisterClick() {
		String firstName = ((EditText) findViewById(R.id.register_firstname)).getText().toString();  
		String lastName = ((EditText) findViewById(R.id.register_lastname)).getText().toString();
		String username = ((EditText) findViewById(R.id.register_username)).getText().toString();  
		String password = ((EditText) findViewById(R.id.register_password)).getText().toString();  
		String email = ((EditText) findViewById(R.id.register_email)).getText().toString();  
		String phone = ((EditText) findViewById(R.id.register_phone)).getText().toString();  
		String zipCode = ((EditText) findViewById(R.id.register_zipcode)).getText().toString();
		presenter.handleRegisterClick(firstName, lastName, username, password, email, phone, zipCode);
	}
}